#include "Ellipsoid.h"

namespace OCPP
{
	namespace Cesium
	{
		const Ellipsoid Ellipsoid::MOON(
			CesiumMath::LUNAR_RADIUS,
			CesiumMath::LUNAR_RADIUS,
			CesiumMath::LUNAR_RADIUS
		);
		const Ellipsoid Ellipsoid::WGS84 = Ellipsoid(6378137.0, 6378137.0, 6356752.3142451793);
		const Ellipsoid Ellipsoid::UNIT_SPHERE = Ellipsoid(1.0, 1.0, 1.0);

		Cartesian2 Ellipsoid::getLocalCurvature(Cartesian3 surfacePosition) {
			Cartesian2 result;
			auto primeVerticalEndpoint = getSurfaceNormalIntersectionWithZAxis(
				surfacePosition,
				0.0
			);
			auto primeVerticalRadius = Cartesian3::distance(
				surfacePosition,
				primeVerticalEndpoint
			);
			// meridional radius = (1 - e^2) * primeVerticalRadius^3 / a^2
			// where 1 - e^2 = b^2 / a^2,
			// so meridional = b^2 * primeVerticalRadius^3 / a^4
			//   = (b * primeVerticalRadius / a^2)^2 * primeVertical
			auto radiusRatio =
				(_minimumRadius * primeVerticalRadius) / (_maximumRadius * _maximumRadius);
			auto meridionalRadius = primeVerticalRadius * (radiusRatio * radiusRatio);

			return Cartesian2::fromElements(
				1.0 / primeVerticalRadius,
				1.0 / meridionalRadius
			);
		};
	}
}

